package org.tc.feign.storefront;

import org.gdtc.storefront.entity.Problemcommodity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.tc.feign.service.FeignProblemService;
import org.tc.feign.service.FeignProductService;

import java.util.List;

@RequestMapping("/Problem")
@RestController
@CrossOrigin(origins = {"*"}, methods = {RequestMethod.GET, RequestMethod.POST}, allowCredentials = "true")
public class FeignProblemController {
    @Autowired
    private FeignProblemService feignProblemService;
    @Autowired
    private FeignProductService feignProductService;

    /**
     * 查询全部没有处理的问题商品
     * @param storeid
     * @return
     */
    @RequestMapping("/QueryProblemtoState")
    @ResponseBody
    public List<Problemcommodity>QueryProblemtoState(Integer storeid){
        List<Problemcommodity> list=feignProblemService.QueryProblemtoState(1);
        return list;
    }

    /**
     * 修改问题仓库状态 0未处理  1已处理（把问题数量添加到商品数量） 2不处理
     * @param state
     * @param id
     * @return
     */
    @RequestMapping("/UpdProblemtoState")
    @ResponseBody
    public int UpdProblemtoState(Integer state,Integer id)
    {
        int count=feignProblemService.UpdProblemtoState(state, id);
        if (state==1)
        {
            int prostock=feignProblemService.QueryStock(id);
            int commstock=feignProblemService.QueryCommtoStock(id);
            int stock=prostock+commstock;
            int commid=feignProblemService.QueryCommodityId(id);
            int upd=feignProductService.UpdtoPro(stock,commid);
            return upd;
        }
        return count;
    }

    /**
     * 根据状态筛选问题商品仓库
     * 0未处理  1已处理（把问题数量添加到商品数量） 2不处理
     * @param state 状态
     * @param storeid 分店ID
     * @return
     */
    @RequestMapping("/QueryProblemtoone")
    public List<Problemcommodity> QueryProblemtoone(Integer state,Integer storeid)
    {
        List<Problemcommodity> list=feignProblemService.QueryProblemtoone(state, storeid);
        return list;
    }
}
